The Memory Game

In this game, players try to memorize a sequence as it grows longer and longer and longer. Tap on the "Start Game" button to begin. Wait and the game will show you the first move. Tap that box. The game will then show you the first and second move. Tap those boxes. Each time the sequence grows longer. Watch the text box. It will tell you what to do next.

Discussion

The memory game makes extensive use of timed delays. The playing squares pause before and after they flash brighter. The status bar pauses after saying "correct" and before returning to "watch this sequence." The repeating sequence player waits a few seconds to allow attention to return to the playing board. JavaScript programmers must pay close attention to timing when using these sorts of delays.

For example, in playSequence, the sequence plays with timed pauses including a delay before prompting the user to begin.


function playSequence(i)
{
    eval("parent.JCcolor"+sequence.substring(i,i+1)+".flash()")
    if ((i+1) < sequence.length)
        SeqTimeOutID = window.setTimeout('playSequence('+(i+1)+')',1000)
    else
        SeqTimeOutID = window.setTimeout(
            'document.forms[0].gameStatus.value="Now you try it..."', 1000)
}

Copyright ©1998 by Charles River Media, All Rights Reserved